package cn.nexd.location.collector.core;

import android.content.Context;

import cn.nexd.location.collector.NexdCollector;
import cn.nexd.location.collector.NexdCollectorConfig;

/**
 * Created by codngfish on 15/10/19.
 */
public abstract class BluetoothCollector extends Collector {

    private static final String ANDROID_PERMISSION_BLUETOOTH = "android.permission.BLUETOOTH";
    private static final String ANDROID_PERMISSION_BLUETOOTH_ADMIN = "android.permission.BLUETOOTH_ADMIN";

    private BluetoothCollectorListener bluetoothCollectorListener;

    protected BluetoothCollector(Context context, NexdCollectorConfig collectorConfig) {
        super(context, collectorConfig);
    }

    public BluetoothCollector(Context context, NexdCollectorConfig collectorConfig, BluetoothCollectorListener bluetoothCollectorListener) {
        this(context, collectorConfig);
        this.bluetoothCollectorListener = bluetoothCollectorListener;
    }

    @Override
    protected boolean checkPermission() {
        boolean checkResult = checkPermission(ANDROID_PERMISSION_BLUETOOTH) && checkPermission(ANDROID_PERMISSION_BLUETOOTH_ADMIN);
        if (!checkResult) {
            bluetoothCollectorListener.onStop(getTaskId(), System.currentTimeMillis(), NexdCollector.COLLECTOR_TASK_STOP_TYPE_PERMISSION_UNAVAILABLE, NexdCollector.COLLECTOR_TASK_STOP_MESSAGE_PERMISSION_UNAVAILABLE + "( BLUETOOTH )");
        }
        return checkResult;
    }
}
